package qingke.struts.example.filter;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class ValidateFilter implements Filter{

	public void init(FilterConfig filterConfig) throws ServletException {
		
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		   
		   printAttribute(request,"before chain do filter");
		   chain.doFilter(request, response);
		   printAttribute(request,"after chain do filter");
		
	}
	
	private void printAttribute(ServletRequest request,String phase){
		Enumeration<String> names=request.getAttributeNames();
		System.out.println("current phase"+phase);
		while(names.hasMoreElements()){
			String name =names.nextElement();
			System.out.println("req attr "+name+"="+request.getAttribute(name));
		}
	}

	public void destroy() {
		// TODO Auto-generated method stub
		
	}

}
